package shiyanliu;

public class Student extends Person {
	private String Zhuanye;
    private Course[] courses;
    public Student() {
        courses = new Course[3];
    }
    public Student(int stuId,String stuName,String sex,String minzu,String zhuanye) {
        this.Id = stuId;
        this.Name = stuName;
        this.sex = sex;
        this.setZhuanye(zhuanye);
        courses = new Course[3];
    }

	public String getZhuanye() {
		return Zhuanye;
	}
	public void setZhuanye(String zhuanye) {
		Zhuanye = zhuanye;
	}
    public boolean Selected(Course course){
        boolean cnt=false;
        for(Course c:courses){
            if(c==course){
                cnt=true;
                break;
            }
        }
        return cnt;
    }
    public boolean Null(Course course){
        boolean cnt=false;
        for(Course c:courses){
            if(c==null){
                cnt=true;
                break;
            }
        } 
        return cnt;
    }
    
    public boolean addCourse(Course course){
        boolean cnt=false;
        if(!Selected(course)&&Null(course)){
            for(int i=0;i<this.courses.length;i++){
                if(courses[i]==null){
                    courses[i]=course;
                    course.addStudent(this);     
                    cnt=true;
                    break;
                }
            }
        }
        return cnt;
    }
    
    public boolean removeCourse(Course course){
        boolean cnt=false;
        if(Selected(course)){
            for(int i=0;i<this.courses.length;i++){
                if(courses[i]==course){
                    courses[i]=null;
                    course.removeStudent(this); 
                    cnt=true;
                    break;
                }
            }
        }
        return cnt;
    }
    
    public String toString(){
    	StringBuffer str =new StringBuffer();	
    	String str1 = "";
    	String str0 = this.Name+"  "+this.Id+"  "+this.sex+"  "+this.Zhuanye+"\n";
    	for(Course c:courses){
    		if(c!=null){
    			
    		str1 = "课程编号："+c.getId()+"\n所选课程："+c.getName()+"\n上课地点："+c.getDestination()+"\n上课时间："+c.getTime()+"\n";
    		str = str.append(str1);
    		}
    	}	
    	String str3 =str0 + str.toString() ;
    	 return str3;
}
  

}
